home *** CD-ROM | disk | FTP | other *** search
/ Mac Expert 1995 Winter / Mac Expert - Winter 95.iso / Les fichiers / Utilitaires divers / Divers / NeXT WDef III 3.1 ƒ / Source / NeXT wdef.c next >
Encoding:
C/C++ Source or Header  |  1993-04-20  |  33.4 KB  |  1,218 lines  |  [TEXT/KAHL]

  1. /*
  2.             ——————————————————————————————
  3.             My Window Definition Procedure
  4.             ——————————————————————————————
  5.             
  6.             This is that odd window.
  7.             
  8.             ————————
  9.             89/04/20
  10.             ————————
  11.             
  12.             1.0      89/03/31    First draft based on clock window def proc (+A5 games ).
  13.                   89/04/05    Fixed problem with zoom box hilite
  14.                   89/04/06    Fixed zooming
  15.                   89/04/07    Minor changes in draw, chose from two gray patterns
  16.                             to avoid odd mismatches in window dragged onscreen 
  17.                             from offscreen, added proper plainDBox & altDBoxProc 
  18.                             variations, special cased zero width titles.
  19.             1.1      89/04/09    Odd half erased scroll bar startup MPW adjusted
  20.                             [see DrawMyGrowIcon()]
  21.             1.2      89/04/09    Fixed problem with userState updates. Working on colors!
  22.                   89/04/11    Changed size box to chevrons.
  23.                   89/04/12    Made sure inGrow only returned on hilited windows.
  24.                   89/04/20    Added Apples screenBits workaround and scroll area 
  25.                               to grow image.
  26.             2.0   89/11/10  Finished color additions and cleaned up other
  27.                             assorted bugs. JNP
  28.             
  29.                             Changes made by Josh Pritikin ( 11.10.89 ):
  30.                     1. In CalculateMyWindow I added a test to see if we have a color window.
  31.                     2. I removed the ugly StuffHex calls and speeded the pattern packing up.
  32.                     3. I added a gunk of code and special casing to totally support ColorQD!
  33.                     4. The code is admitably gross in some (most) places but it works and should
  34.                         serve as an example of what not to make your code look like.
  35.  
  36.                         GEnie:            J.Pritikin
  37.                         AppleLink:        D4991    ( <- this will change soon )
  38.                         Internet:        6500stom@ucsbuxa.ucsb.edu
  39.                         
  40.             3.0   93/03/22    Updated for full color support. Rewrote code for Think C 5.x.
  41.                             
  42.                             Changes made by Anthony D. Saxton ( 2/26/93 ):
  43.                     1.    Rewrote code throughout for more efficient use of Think C 5.x.
  44.                     2.    Added Color button Icons for 2, 4 and 8 bit modes.
  45.                     3.    Added support for colorized windows as well as Apples "Color" cdev.
  46.                     4.    Added support for ALL documented window types & frames for the others!
  47.                     5.    Corrected Icon bug and added 3D movement!
  48.                     6.    Corrected GoAway button presence in movable dialog windows.
  49.             
  50.             3.1      93/04/13    Corrected some memory wasting code.
  51.                             Converted the Icon Color Table to a global.
  52.                             Corrected Colors in 2-bit mode.
  53.                     
  54.         The Copyright Notice in “CopyRight()” Is Not To Be Removed! Use Of This Code In
  55.         Commercial Software By License Only. Contact Anthony D. Saxton, Of Elenay™ Creations
  56.         For Licensing Information. Use Of This Code In FreeWare, Requires Only Contact Of
  57.         Elenay™ Creations. This Copyright Applies To All Code Segments Of This WDEF. 
  58.         
  59.         All Changes Are Copyright ©1993, by Elenay Creations
  60.                                             5686 Big Sea Street
  61.                                             Las Vegas, NV, USA
  62.                                                                 89110
  63.                                             (702) 453-0270
  64.                             
  65.                         AOL:            Elenay
  66.                         Internet:        elenay_creations@tcs.las-vegas.nv.us
  67.             
  68.             —————————————————————————————————————————————————
  69.               Public Domain 1989 by Appropriate Technology
  70.             —————————————————————————————————————————————————
  71.             Changes - Copyright ©1993 by Elenay™ Creations
  72.             —————————————————————————————————————————————————
  73.             
  74.             Please send a copy of changes/improvements to:
  75.             
  76.             Eric Celeste, Appropriate Technology, 358 North Parkview, Columbus, OH 43209, USA.
  77.             CompuServe: 76146,724. MacNET: Celeste.
  78.             
  79.             ——————————————————————————————————————————————————————————————————————
  80.             Note: This WDEF is coded in THINK C 5.0.3 from Think Technologies
  81.             ——————————————————————————————————————————————————————————————————————
  82.  
  83.  
  84. */
  85.  
  86. #include "NeXT wdef.h"
  87.  
  88. pascal long main( int variation, WindowPtr window, int message, long parameter )
  89. {
  90.     long    result = 0L;            /* the return code for the function */
  91.     THz        saveZone;
  92.     
  93.     saveZone = GetZone();
  94.     if ( MFRunning() )
  95.         SetZone( SystemZone() );
  96.     
  97.     switch( message ) 
  98.     {
  99.     case( wDraw ):
  100.         DrawMyWindow( variation, window, parameter );
  101.         break;
  102.     case( wHit ):
  103.         result = HitMyWindow( variation, window, parameter );
  104.         break;
  105.     case( wCalcRgns ):
  106.         CalculateMyWindow( variation, window, parameter );
  107.         break;
  108.     case( wNew ):
  109.         SetupWindow( variation, window, parameter );
  110.         break;
  111.     case( wDispose ):
  112.         KillWindow( variation, window, parameter );
  113.         break;
  114.     case( wGrow ):
  115.         GrowMyWindow( variation, window, parameter );
  116.         break;
  117.     case( wDrawGIcon ):
  118.         DrawMyGrowIcon( variation, window, parameter );
  119.         break;
  120.     }
  121.     
  122.     SetZone( saveZone );
  123.     return( result );
  124. }
  125.  
  126. /*————————————————————
  127.             is MultiFinder Running?
  128. ————————————————————*/
  129. Boolean    MFRunning()
  130. {
  131.     Boolean        result;
  132.     SysEnvRec    theWorld;
  133.     
  134.     result = false;
  135.     if ( !SysEnvirons( 1, &theWorld ) )
  136.         result = ( theWorld.machineType >= 0 ) &&
  137.                     ( NGetTrapAddress( OSDispatchTrapNum, ToolTrap ) !=
  138.                                                 NGetTrapAddress( UnImplTrapNum, ToolTrap ) );
  139.     return( result );
  140. }
  141.  
  142. /*————————————————————
  143.             create an RGB gray of this brightness.
  144. ————————————————————*/
  145. RGBColor PackGray( int brightness )
  146. {
  147.     RGBColor    gray;
  148.     
  149.     gray.red = gray.green = gray.blue = brightness;
  150.     return gray;
  151. }
  152.  
  153. /*————————————————————
  154.             where was my window hit?
  155. ————————————————————*/
  156. long HitMyWindow( int variation, WindowPtr window, long parameter )
  157. {
  158.     Point    hitLocation;
  159.     long    result;
  160.     
  161.     result = wNoHit;
  162.     
  163.     SetPt( &hitLocation, LoWord( parameter ), HiWord( parameter ) );
  164.     
  165.     if ( PtInRgn( hitLocation, theWindow.strucRgn ) )
  166.     {
  167.         Rect    windowRect,
  168.                 thisRect;
  169.                 
  170.         windowRect = (**theWindow.strucRgn).rgnBBox;
  171.         
  172.         if ( PtInRgn( hitLocation, theWindow.contRgn ) )
  173.         {
  174.             result = wInContent;                    /* in the content region */
  175.             
  176.             if ( theWindow.hilited )
  177.                 if ( (variation & 7) == documentProc )
  178.                 {
  179.                     SetRect( &thisRect,
  180.                         windowRect.right - 17,
  181.                         windowRect.bottom - 17,
  182.                         windowRect.right - 3,
  183.                         windowRect.bottom - 3
  184.                     );
  185.                     if ( PtInRect( hitLocation, &thisRect ) )
  186.                         result = wInGrow;
  187.                 }
  188.         } else
  189.         {
  190.             switch( variation & 7 )
  191.             {
  192.             case( documentProc ):
  193.             case( noGrowDocProc ):
  194.             case( movableDBoxProc ):
  195.             
  196.                 result = wInDrag;                        /* in the drag area unless */
  197.                 
  198.                 if ( theWindow.hilited )
  199.                 {
  200.                     if ( theWindow.goAwayFlag && variation != movableDBoxProc )
  201.                     {
  202.                         SetRect( &thisRect,
  203.                             windowRect.left + 5,
  204.                             windowRect.top + 5,
  205.                             windowRect.left + 18,
  206.                             windowRect.top + 18
  207.                         );
  208.                         if ( PtInRect( hitLocation, &thisRect ) )
  209.                             result = wInGoAway;
  210.                     }
  211.                     if ( result == wInDrag && theWindow.zoomFlag )
  212.                     {
  213.                         SetRect( &thisRect,
  214.                             windowRect.right - 17,
  215.                             windowRect.top + 5,
  216.                             windowRect.right - 4,
  217.                             windowRect.top + 18
  218.                         );
  219.                         if ( PtInRect( hitLocation, &thisRect ) && theWindow.dataHandle  )
  220.                         {
  221.                             thisRect = (**theWindow.contRgn).rgnBBox;
  222.                             if ( EqualRect ( &(wDataHandle.stdState), &thisRect ) )
  223.                                 result = wInZoomIn;
  224.                             else
  225.                             {
  226.                                 wDataHandle.userState = thisRect;
  227.                                 result = wInZoomOut;
  228.                             }
  229.                         } /* in the zoom box */
  230.                         
  231.                     } /* still dragging & zoomable */
  232.                     
  233.                 } /* a hilited window */
  234. /* Uncomment this routine for "Apple's specs" operation !
  235.                 
  236.                 if ( result == wInDrag )
  237.                 {
  238.                     thisRect = windowRect;
  239.                     thisRect.top = (**theWindow.contRgn).rgnBBox.top;
  240.                     if ( PtInRect( hitLocation, &thisRect ) )
  241.                         result = wNoHit;                    // according to Apple's specs
  242. //                        result = wInContent;                // alternate result
  243.                 }  // below title bar
  244. */
  245.                 break;
  246.                 
  247.             }    /* a moveable window */
  248.             
  249.         } /* else not in content region */
  250.         
  251.     } /* in the structure region */
  252.     
  253.     return( result );
  254. } /* end of HitMyWindow() */
  255.  
  256. /*————————————————————
  257.             calculate the regions of my window
  258. ————————————————————*/
  259. CalculateMyWindow( int variation, WindowPtr window, long parameter )
  260. {
  261.     Rect    windowRect;
  262.     
  263.     windowRect = window->portRect;
  264.                                             /* a fix for CWindowRecords */
  265.     if( window->portBits.rowBytes < colorWindow ) /* Color Window? */
  266.         OffsetRect( &windowRect, -window->portBits.bounds.left, -window->portBits.bounds.top );
  267.     else
  268.     {
  269.         Rect    portR;
  270.         
  271.         portR = (**(*(CWindowPtr)window).portPixMap).bounds;
  272.         OffsetRect( &windowRect,-portR.left, -portR.top );
  273.     }
  274.     
  275.     RectRgn( theWindow.contRgn, &windowRect );
  276.     
  277.     if ( (variation & 8) && !EqualRect( &(wDataHandle.stdState),&windowRect ) )
  278.         wDataHandle.userState = windowRect;
  279.  
  280.     switch ( variation & 7 )
  281.     {
  282.     case ( documentProc ):                        /* a regular window */
  283.     case ( noGrowDocProc ):                        /* a regular window with no growing */
  284.     case ( movableDBoxProc ):                    /* a moveable dialog with no growing or close*/
  285.         OpenRgn();
  286.             InsetRect( &windowRect, -4, -4 );
  287.             windowRect.top -= 16;                /* add room for the title bar */
  288.             MoveTo( windowRect.left, windowRect.top );
  289.             LineTo( windowRect.left, windowRect.bottom-2 );
  290.             LineTo( windowRect.left+2, windowRect.bottom );
  291.             LineTo( windowRect.right, windowRect.bottom );
  292.             LineTo( windowRect.right, windowRect.top+2 );
  293.             LineTo( windowRect.right-2, windowRect.top );
  294.             LineTo( windowRect.left, windowRect.top );
  295.         CloseRgn( theWindow.strucRgn );
  296.         break;
  297.     case ( dBoxProc ):                            /* dialog box variation */
  298.         OpenRgn();
  299.             InsetRect( &windowRect, -8, -8 );
  300.             MoveTo( windowRect.left, windowRect.top );
  301.             LineTo( windowRect.left, windowRect.bottom-2 );
  302.             LineTo( windowRect.left+2, windowRect.bottom );
  303.             LineTo( windowRect.right, windowRect.bottom );
  304.             LineTo( windowRect.right, windowRect.top+2 );
  305.             LineTo( windowRect.right-2, windowRect.top );
  306.             LineTo( windowRect.left, windowRect.top );
  307.         CloseRgn( theWindow.strucRgn );
  308.         break;
  309.     case ( altDBoxProc ):                        /* shadow box variation */
  310.     case ( altDBoxProc + 4 ):                    /* remain consistant W/ Apple */
  311.         OpenRgn();
  312.             InsetRect( &windowRect, -1, -1 );
  313.             MoveTo( windowRect.left, windowRect.top );
  314.             LineTo( windowRect.left, windowRect.bottom );
  315.             LineTo( windowRect.left+2, windowRect.bottom );
  316.             LineTo( windowRect.left+2, windowRect.bottom+2 );
  317.             LineTo( windowRect.right+2, windowRect.bottom+2 );
  318.             LineTo( windowRect.right+2, windowRect.top+2 );
  319.             LineTo( windowRect.right, windowRect.top+2 );
  320.             LineTo( windowRect.right, windowRect.top );
  321.             LineTo( windowRect.left, windowRect.top );
  322.         CloseRgn( theWindow.strucRgn );
  323.         break;
  324.     default:                                /* plain box variation (plainDBox) and others */
  325.         InsetRect( &windowRect, -1, -1 );
  326.         RectRgn( theWindow.strucRgn, &windowRect );
  327.         break;
  328.     }
  329.         
  330. } /* end of CalculateMyWindow() */
  331.  
  332. /*————————————————————
  333.             set up the window
  334. ————————————————————*/
  335. SetupWindow( int variation, WindowPtr window, long parameter )
  336. {
  337.     theWindow.dataHandle = nil;
  338.     
  339.     theWindow.dataHandle = NewHandle( (long)sizeof( WSDRecord ) );
  340.     wCTHandle = nil;                                    // initialize CTable
  341.         
  342.     if ( variation == ( documentProc+8 ) || variation == ( noGrowDocProc+8 ) ||
  343.                                                             variation == ( movableDBoxProc+8 ) )
  344.     {
  345.         theWindow.zoomFlag = true;
  346.         if ( theWindow.dataHandle )
  347.         {        
  348.             OSErr        err;
  349.             SysEnvRec    thisWorld;
  350.             Rect        thisRect;
  351.             
  352.             err = SysEnvirons( 1, &thisWorld );
  353.             if ( !err && thisWorld.hasColorQD )
  354.             {
  355.                 GDHandle    thisDevice;
  356.                 
  357.                 thisDevice = GetMainDevice();
  358.                 thisRect = (**thisDevice).gdRect;
  359.                 thisRect.top += MBarHeight;
  360.             } else
  361.             {
  362.                 GrafPtr        savePort;
  363.                 GrafPort    tempPort;
  364.                 
  365.                 GetPort( &savePort );                /* finding screenBits w/o globals */
  366.                 OpenPort( &tempPort );
  367.                 thisRect = tempPort.portRect;
  368.                 SetPort( savePort ); 
  369.                 ClosePort( &tempPort );
  370.                 thisRect.top += MBarHeight;            /* make way for the menubar */
  371.             }
  372.             InsetRect( &thisRect, 4, 4 );            /* make way for edges */
  373.             thisRect.top += 16;                        /* make way for what's left of title */
  374.             wDataHandle.stdState = thisRect;
  375.             wDataHandle.userState = thisRect;
  376.         }
  377.     } else
  378.         theWindow.zoomFlag = false;
  379.         
  380.     buttonState = 0;
  381.     
  382. } /* end of SetupWindow() */
  383.  
  384. /*————————————————————
  385.             kill the window
  386. ————————————————————*/
  387. KillWindow( int variation, WindowPtr window, long parameter )
  388. {
  389.     if ( theWindow.dataHandle  )
  390.     {
  391.         if ( wCTHandle )
  392.         {
  393.             DisposeHandle( wCTHandle );
  394.             wCTHandle = nil;
  395.         }
  396.         DisposHandle( theWindow.dataHandle );
  397.         theWindow.dataHandle = nil;
  398.     }
  399. } /* end of KillWindow() */
  400.  
  401. /*————————————————————
  402.             draw the growing outline, the pen is already set
  403. ————————————————————*/
  404. GrowMyWindow( int variation, WindowPtr window, long parameter )
  405. {
  406.     Rect        growingRect;
  407.     
  408.     growingRect = *(RectPtr)parameter;
  409.     
  410.     growingRect.top -= 20;                                    /* out to full size */
  411.     growingRect.left -= 4;
  412.     growingRect.bottom += 4;
  413.     growingRect.right += 4;
  414.     
  415.     FrameRect( &growingRect );                                /* the frame */
  416.     
  417.     growingRect.top += 19;
  418.     
  419.     MoveTo( growingRect.left, growingRect.top );            /* the title bar area */
  420.     LineTo( growingRect.right, growingRect.top );
  421.     
  422.     MoveTo( growingRect.right - 19, growingRect.top );         /* the scroll area */
  423.     LineTo( growingRect.right - 19, growingRect.bottom );
  424.     MoveTo( growingRect.left, growingRect.bottom - 19 );
  425.     LineTo( growingRect.right, growingRect.bottom - 19 );
  426.     
  427. } /* end of GrowMyWindow() */
  428.  
  429. /*————————————————————
  430. draw the size box and the scroll frame
  431. ————————————————————*/
  432. DrawMyGrowIcon( int variation, WindowPtr window, long parameter )
  433. {
  434.     SysEnvRec        thisWorld;
  435.     Boolean            hasColorQD;
  436.     Rect            thisRect;
  437.     RGBColor        myRGB;
  438.     RgnHandle        saveClip,
  439.                     tempRgn;
  440.     
  441.     
  442.     SetPort( window );
  443.     
  444.     if ( !SysEnvirons( 1, &thisWorld ) )
  445.         hasColorQD = thisWorld.hasColorQD;
  446.     else
  447.         hasColorQD = false;
  448.     
  449.     if ( hasColorQD )
  450.     {
  451.         AuxWinHandle    theAuxWin;
  452.         
  453.         theAuxWin = nil;
  454.         GetAuxWin( window, &theAuxWin );
  455.         if ( theAuxWin )
  456.         {
  457.             
  458. /*        The code below makes sure the System 7 colors are found even when the window color
  459.             table is defined with only 5 colors! This determines if the Grow Icon will be drawn
  460.             in color or b/w. */
  461.                 
  462.             if ( auxCTable->ctSize < 12 )
  463.                 GetAuxWin( nil, &theAuxWin );
  464.                 
  465.             if ( auxCTable->ctSize >= 12 )
  466.                 myRGB =  auxCTable->ctTable[12].rgb;
  467.             else
  468.                 myRGB.red = 0xFFFF;                // Don't force b/w if Color cdev not used…
  469.         }
  470.     }
  471.     
  472. /*————————————————————
  473. draw scroll bar frame
  474. ————————————————————*/
  475.     thisRect = window->portRect;
  476.     thisRect.left = thisRect.right - 15;
  477.     MoveTo( thisRect.left, thisRect.top );
  478.     LineTo( thisRect.left, thisRect.bottom );
  479.  
  480.     thisRect.top = thisRect.bottom - 15;
  481.     thisRect.left = window->portRect.left;
  482.     MoveTo( thisRect.left, thisRect.top );
  483.     LineTo( thisRect.right, thisRect.top );
  484.     
  485.     thisRect.left = thisRect.right - 14;
  486.     thisRect.top++;
  487.     EraseRect( &thisRect );
  488.     
  489.     /*————————————————————
  490.     draw the sizing box 
  491.     ————————————————————*/
  492.  
  493.     saveClip = NewRgn();
  494.     tempRgn = NewRgn();
  495.     GetClip( saveClip );
  496.     
  497.     if ( hasColorQD && window->portBits.rowBytes < colorWindow )    // Color Window?
  498.     {
  499.         CGrafPtr    wPort;
  500.         
  501.         thisRect = (**theWindow.contRgn).rgnBBox;
  502.         thisRect.left = thisRect.right - 15;
  503.         thisRect.top = thisRect.bottom - 15;    
  504.         thisRect.right += 1;
  505.         thisRect.bottom += 1;
  506.         GetCWMgrPort( &wPort );
  507.         SetPort( wPort );
  508.     } else
  509.     {
  510.         thisRect.right += 2;
  511.         thisRect.bottom += 2;
  512.     }
  513.  
  514.  
  515.     if ( theWindow.hilited )
  516.     {
  517.         if( hasColorQD )
  518.         {
  519.             GDHandle    aDevice;
  520.             
  521.             aDevice = GetDeviceList();
  522.             do
  523.             {
  524.                 if ( TestDeviceAttribute( aDevice, screenDevice ) &&
  525.                                                     TestDeviceAttribute( aDevice, screenActive ) )
  526.                 {
  527.                     HLockHi( aDevice );
  528.                     if ( RectInRgn( &(**aDevice).gdRect, saveClip ) )
  529.                     {
  530.                         Handle    theColors;
  531.                         
  532.                         theColors = wCTHandle;
  533.                         RectRgn( tempRgn, &(**aDevice).gdRect );
  534.                         SectRgn( saveClip, tempRgn, tempRgn );
  535.                         SetClip( tempRgn );
  536.                         if ( (**(**aDevice).gdPMap).cmpSize >= 2 && (myRGB.red+myRGB.green))
  537.                             PlotCICN( thisRect,
  538.                                 "\xEA\xAA\xAA\xA8\x95\x41\x55\x48"
  539.                                 "\x95\x4A\x55\x48\x95\x4A\x01\x48"
  540.                                 "\x95\x4A\x2A\x48\x80\x1A\x2A\x48"
  541.                                 "\x8A\xAA\x2A\x48\x9A\xAA\x2A\x48"
  542.                                 "\x95\x55\x2A\x48\x94\x00\x6A\x48"
  543.                                 "\x94\xAA\xAA\x48\x95\xAA\xAA\x48"
  544.                                 "\x95\x55\x55\x48\x80\x00\x00\x18"
  545.                                 "\xFF\xFF\xFF\xF8\x00\x00\x00\x00",
  546.                                 (**(**aDevice).gdPMap).cmpSize >2 ? theColors : nil );    // The Color Grow Icon!
  547.                         else
  548.                             PlotSICN( thisRect, 
  549.                                 "\xFF\xFC\xD1\x52\xAB\xA8\xD3\x12"
  550.                                 "\xAB\x78\x83\x72\xBF\x78\xFF\x72"
  551.                                 "\xAA\x78\xC0\x72\xAF\xF8\xDF\xF2"
  552.                                 "\xAA\xA8\x80\x02\xFF\xFE\x00\x00"
  553.                             );                                        // The b/w Grow Icon!
  554.                     }
  555.                     HUnlock( aDevice );
  556.                 }
  557.             } while ( aDevice = GetNextDevice( aDevice ) );
  558.         } else
  559.             PlotSICN( thisRect, 
  560.                 "\xFF\xFC\xD1\x52\xAB\xA8\xD3\x12"
  561.                 "\xAB\x78\x83\x72\xBF\x78\xFF\x72"
  562.                 "\xAA\x78\xC0\x72\xAF\xF8\xDF\xF2"
  563.                 "\xAA\xA8\x80\x02\xFF\xFE\x00\x00"
  564.             );                                                    // The b/w Grow Icon Again!
  565.     }
  566.     
  567.     SetClip( saveClip );
  568.     DisposeRgn( saveClip );
  569.     DisposeRgn( tempRgn );
  570.  
  571.     SetPort( window );
  572.  
  573. } /* end of DrawMyGrowIcon() */
  574.  
  575. /*————————————————————
  576.             draw the frame w/ color shadowing.
  577. ————————————————————*/
  578. DrawFrame( PatsPtr pat, Rect frame, int width, int drawColor )
  579. {
  580.     frame.right -= 2;
  581.     frame.bottom -= 2;
  582.     
  583.     PenSize( width, width );
  584.     if ( drawColor )
  585.         RGBForeColor( drawColor - 1 ? &pat->cFrameL : &pat->cLight );
  586.     else
  587.         PenPat( &pat->white );
  588.     FrameRect( &frame );
  589.     
  590.     OffsetRect( &frame, 2, 2 );
  591.     if ( drawColor )
  592.         RGBForeColor( drawColor - 1 ? &pat->cFrameD : &pat->cDark );
  593.     else
  594.         PenPat( &pat->black );
  595.     FrameRect( &frame );
  596.  
  597.     OffsetRect( &frame, -1, -1 );
  598.     if ( drawColor )
  599.         RGBForeColor( &pat->cGray );
  600.     else
  601.         PenPat( &pat->gray );
  602.     FrameRect( &frame );
  603. } /* end of DrawFrame() */
  604.  
  605. /*————————————————————
  606.             draw an empty pane w/ shadowing
  607. ————————————————————*/
  608. DrawPane( PatsPtr pat, Rect thisRect, int drawColor )
  609. {
  610.     /* fill the area with white */
  611.     if ( drawColor )
  612.     {
  613.         RGBForeColor( &pat->cTitle );
  614.         PenPat( &pat->black );
  615.     } else
  616.         PenPat( &pat->white );
  617.     PaintRect( &thisRect );
  618.     
  619.     /* add the bottom shadow */
  620.     PenSize( 1, 1 );
  621.     if ( drawColor )
  622.         RGBForeColor( drawColor - 1 ? &pat->cFrameL : &pat->cLight );
  623.     else
  624.         PenPat( &pat->black );
  625.     MoveTo( thisRect.left+1, thisRect.bottom-1 );
  626.     LineTo( thisRect.right-1, thisRect.bottom-1 );
  627.     LineTo( thisRect.right-1, thisRect.top+1 );
  628.     
  629.     /* add the top shadow */
  630.     if ( drawColor )
  631.         RGBForeColor( drawColor - 1 ? &pat->cFrameD : &pat->cDark );
  632.     MoveTo( thisRect.left, thisRect.bottom-1 );
  633.     LineTo( thisRect.left, thisRect.top );
  634.     LineTo( thisRect.right-1, thisRect.top );
  635. } /* end of DrawPane() */
  636.  
  637. /*————————————————————
  638.             draw the title into the pane.
  639. ————————————————————*/
  640. DrawWindowTitle( WindowPtr window, Rect titleRect, PatsPtr pat, Boolean hilited, int drawColor )
  641. {
  642.     int            saveFont,
  643.                 saveSize;
  644.     Style        saveFace;
  645.     Str255        windowTitle;
  646.     int            titleWidth;
  647.     GrafPtr        wPort;
  648.     
  649.     GetPort( &wPort );
  650.     saveFont = wPort->txFont;
  651.     saveSize = wPort->txSize;
  652.     saveFace = wPort->txFace;
  653.  
  654.     TextFont( geneva );
  655.     TextSize( 9 );
  656.     TextFace( plain );
  657.     
  658.     GetWTitle( window, windowTitle );
  659.     
  660.     titleWidth = StringWidth( windowTitle );
  661.     
  662.     if ( titleWidth > 0 )
  663.     {
  664.         RgnHandle    saveClip,
  665.                     myClip;
  666.  
  667.         titleWidth += 12;                        /* enough for edges */
  668.     
  669.         if ( (titleRect.right - titleRect.left) > titleWidth )
  670.             titleRect.right = titleRect.left + titleWidth;
  671.         
  672.         if ( hilited ) DrawPane( pat, titleRect, drawColor );
  673.         
  674.         /* now shrink the box & set the clip region in case of a long title */
  675.         saveClip = NewRgn();
  676.         myClip = NewRgn();
  677.         GetClip( saveClip );
  678.         
  679.         InsetRect( &titleRect, 1, 1 );
  680.         RectRgn( myClip, &titleRect );
  681.         SectRgn( saveClip, myClip, myClip );
  682.         SetClip( myClip );
  683.         
  684.         /* now position ourselves & draw the title */
  685.         PenPat( &pat->black );
  686.         if ( drawColor )
  687.         {
  688.             if ( hilited )
  689.             {
  690.                 RGBForeColor( &pat->cText );
  691.                 RGBBackColor( &pat->cTitle );
  692.             } else
  693.             {
  694.                 RGBForeColor( &pat->cWhite );
  695.                 RGBBackColor( &pat->cGray );
  696.             }
  697.         }
  698.         
  699.         MoveTo( titleRect.left + 5, titleRect.bottom - 2 );
  700.         DrawString( windowTitle );
  701.         
  702.         SetClip( saveClip );
  703.         DisposeRgn( saveClip );
  704.         DisposeRgn( myClip );
  705.                 
  706.     } /* enough of a title to go with */
  707.     
  708.     TextFont( saveFont );
  709.     TextSize( saveSize );
  710.     TextFace( saveFace );
  711. } /* end of DrawWindowTitle() */
  712.  
  713. /*————————————————————
  714.             animate the close icon.
  715. ————————————————————*/
  716. DrawGoAway( Rect frame, Boolean hilited, int drawColor, Handle theColors )
  717. {
  718.     if ( hilited  )
  719.     {
  720.         if ( drawColor )
  721.             PlotCICN( frame,
  722.                         "\xBF\xFF\xFF\xF9\xEA\xAA\xAA\xAD\xE5\x55\x55\x4D\xE5\x55\x55\x4D"
  723.                         "\xE5\x55\x55\x4D\xE5\x55\x55\x4D\xE5\x00\x00\x4D\xE4\x55\x56\x4D"
  724.                         "\xE4\x55\x56\x4D\xE4\x55\x56\x4D\xE4\x55\x56\x4D\xE4\xAA\xAA\x4D"
  725.                         "\xE5\x55\x55\x4D\xE0\x00\x00\x1D\xBF\xFF\xFF\xF9\x55\x55\x55\x55",
  726.                         drawColor -1 ? theColors : nil );    // goAwayDown
  727.         else
  728.             PlotSICN( frame,
  729.                         "\xFF\xFE\xFF\xFF\xEA\xAA\xD5\x53\xEA\xAA\xD5\x53\xE0\x0A\xC5\x53"
  730.                         "\xEA\xBA\xC5\x53\xEA\xBA\xDF\xF3\xEA\xAA\xC0\x03\xFF\xFE\x55\x55"
  731.                     );    // goAwayDown (b/w)
  732.     } else
  733.     {
  734.         if ( drawColor )
  735.             PlotCICN( frame,
  736.                         "\xBF\xFF\xFF\xF9\xD0\x00\x00\x0D\xC5\x55\x55\x6D\xC5\x55\x55\x6D"
  737.                         "\xC5\x55\x55\x6D\xC5\x55\x55\x6D\xC5\x00\x00\x6D\xC4\x55\x56\x6D"
  738.                         "\xC4\x55\x56\x6D\xC4\x55\x56\x6D\xC4\x55\x56\x6D\xC4\xAA\xAA\x6D"
  739.                         "\xC5\x55\x55\x6D\xCA\xAA\xAA\xAD\xBF\xFF\xFF\xF9\x55\x55\x55\x55",
  740.                         drawColor -1 ? theColors : nil  );    // goAwayUp
  741.         else
  742.             PlotSICN( frame,
  743.                         "\xFF\xFE\x80\x03\xAA\xAE\x95\x57\xAA\xAE\x95\x57\xA0\x0E\x85\x57"
  744.                         "\xAA\xBE\x85\x57\xAA\xBE\x8F\xF7\xAA\xAE\xBF\xFF\xFF\xFE\x55\x55"
  745.                     );    //    goAwayUp (b/w)
  746.     }
  747. } /* end of DrawGoAway() */
  748.  
  749. /*————————————————————
  750.             animate the zoom icon.
  751. ————————————————————*/
  752. DrawZoom( Rect frame, Boolean hilited, int drawColor, Handle theColors )
  753. {
  754.     if ( hilited )
  755.     {
  756.         if ( drawColor )
  757.             PlotCICN( frame,
  758.                         "\xBF\xFF\xFF\xF9\xEA\xAA\xAA\xAD\xE5\x55\x55\x4D\xE5\x00\x00\x4D"
  759.                         "\xE4\x55\x56\x4D\xE4\x55\x56\x4D\xE4\x55\x56\x4D\xE4\x55\x56\x4D"
  760.                         "\xE4\x55\x56\x4D\xE4\x55\x56\x4D\xE4\x55\x56\x4D\xE4\xAA\xAA\x4D"
  761.                         "\xE5\x55\x55\x4D\xE0\x00\x00\x1D\xBF\xFF\xFF\xF9\x55\x55\x55\x55",
  762.                         drawColor -1 ? theColors : nil  );    //    zoomDown
  763.         else
  764.             PlotSICN( frame,
  765.                         "\xFF\xFE\xFF\xFF\xEA\xAA\xC0\x03\xEA\xBA\xC5\x53\xEA\xBA\xC5\x53"
  766.                         "\xEA\xBA\xC5\x53\xEA\xBA\xCF\xF3\xEA\xAA\xC0\x03\xFF\xFE\x55\x55"
  767.                     );    //    zoomDown (b/w)
  768.     } else
  769.     {
  770.         if ( drawColor )
  771.             PlotCICN( frame,
  772.                         "\xBF\xFF\xFF\xF9\xD0\x00\x00\x0D\xC5\x55\x55\x6D\xC5\x00\x00\x6D"
  773.                         "\xC4\x55\x56\x6D\xC4\x55\x56\x6D\xC4\x55\x56\x6D\xC4\x55\x56\x6D"
  774.                         "\xC4\x55\x56\x6D\xC4\x55\x56\x6D\xC4\x55\x56\x6D\xC4\xAA\xAA\x6D"
  775.                         "\xC5\x55\x55\x6D\xCA\xAA\xAA\xAD\xBF\xFF\xFF\xF9\x55\x55\x55\x55",
  776.                         drawColor -1 ? theColors : nil  );    //    zoomUp
  777.         else
  778.             PlotSICN( frame,
  779.                         "\xFF\xFE\x80\x07\xAA\xAE\x80\x17\xAA\xBE\x85\x57\xAA\xBE\x85\x57"
  780.                         "\xAA\xBE\x85\x57\xAA\xBE\x9F\xF7\xAA\xAE\xFF\xFF\xFF\xFE\x55\x55"
  781.                     );
  782.     }
  783. } /* end of DrawZoom() */
  784.  
  785. /*————————————————————
  786.             draw the specified item
  787. ————————————————————*/
  788. DrawOnce( long param, int var, WindowPtr window, Rect windowRect, PatsPtr pat, int drawColor )
  789. {
  790.     Rect        thisRect;
  791.     Handle        theColors;
  792.                 
  793.     theColors = wCTHandle;
  794.     
  795.     switch ( (int)param )
  796.     {
  797.     case ( wNoHit ):
  798.         
  799.         thisRect = windowRect;
  800.  
  801.         PenNormal();
  802.         
  803.         /* ——————————————————————————————————————— now for the more specific parts */
  804.         switch ( var & 7 )
  805.         {
  806.         case ( documentProc ):                    /* a regular window */
  807.         case ( noGrowDocProc ):                    /* a regular window with no grow box */
  808.         case ( movableDBoxProc ):                /* a non-modal dialog */
  809.             DrawFrame( pat, thisRect, 2, drawColor );
  810.             InsetRect( &thisRect, 1, 1 );
  811.             
  812.             thisRect.bottom = thisRect.top + 19;
  813.             if ( drawColor )
  814.             {
  815.                 PenPat( &pat->black );
  816.                 RGBForeColor( &pat->cGray );
  817.             } else
  818.                 PenPat( &pat->gray );
  819.             PaintRect( &thisRect );
  820.             PenPat( &pat->black );
  821.             if ( drawColor )
  822.                 RGBForeColor( drawColor - 1 ? &pat->cFrameD : &pat->cDark );
  823.             PenSize( 1, 1 );
  824.             MoveTo( windowRect.left+3, windowRect.top+19 );
  825.             LineTo( windowRect.right-4, windowRect.top+19 );
  826.  
  827.             if ( theWindow.hilited )
  828.             {
  829.                 /* ——————————————————————————————— the goaway box */
  830.                 if ( theWindow.goAwayFlag  && (var & 7) != movableDBoxProc )
  831.                 {
  832.                     SetRect( &thisRect, 
  833.                         windowRect.left     + 3, 
  834.                         windowRect.top         + 3,
  835.                         windowRect.left     + 19,
  836.                         windowRect.top         + 19
  837.                      );
  838.                     DrawPane( pat, thisRect, drawColor );
  839.                     DrawGoAway( thisRect, false, drawColor, theColors );        
  840.                 }
  841.                 /* ——————————————————————————————— the zoom box */
  842.                 if ( theWindow.zoomFlag )
  843.                 {
  844.                     SetRect( &thisRect, 
  845.                         windowRect.right     - 19, 
  846.                         windowRect.top         + 3,
  847.                         windowRect.right     - 3,
  848.                         windowRect.top         + 19
  849.                      );
  850.                     DrawPane( pat, thisRect, drawColor );
  851.                     DrawZoom( thisRect, false, drawColor, theColors );        
  852.                 }
  853.                 /* ——————————————————————————————— the title */
  854.                 SetRect( &thisRect, 
  855.                     windowRect.left     + 20, 
  856.                     windowRect.top         + 3,
  857.                     windowRect.right     - (( theWindow.zoomFlag ) ? 21 : 3),
  858.                     windowRect.top         + 17
  859.                  );
  860.                 PenSize( 1, 1 );
  861.                 if ( thisRect.right - thisRect.left > 0 )
  862.                     DrawWindowTitle( window, thisRect, pat, true, drawColor );
  863.             } else
  864.             {
  865.                 /* ——————————————————————————————— the blank title bar */
  866.                 if ( !drawColor )
  867.                 {
  868.                     thisRect.top += 2;
  869.                     thisRect.left += 2;
  870.                     thisRect.bottom = thisRect.top + 14;
  871.                     thisRect.right -=2;
  872.                     DrawPane( pat, thisRect, drawColor );
  873.                 }
  874.                 /* ——————————————————————————————— the title */
  875.                 SetRect( &thisRect, 
  876.                     windowRect.left     + 20, 
  877.                     windowRect.top         + 3,
  878.                     windowRect.right     - 19,
  879.                     windowRect.top         + 17
  880.                  );
  881.                 DrawWindowTitle( window, thisRect, pat, false, drawColor );
  882.             }
  883.             break;
  884.         
  885.         case ( dBoxProc ):                        /* dialog box variation */
  886.             DrawFrame( pat, thisRect, 4, drawColor );
  887.             thisRect.right -= 2;
  888.             thisRect.bottom -= 2;
  889.             OffsetRect( &thisRect, 1, 1 );
  890.             InsetRect( &thisRect, 5, 5 );
  891.             PenSize( 2, 2 );
  892.             if ( drawColor )
  893.             {
  894.                 PenPat( &pat->black );
  895.                 RGBForeColor( drawColor - 1 ? &pat->cFrameL : &pat->cLight );
  896.             } else
  897.                 PenPat( &pat->white );
  898.             FrameRect( &thisRect );
  899.             break;
  900.         case ( altDBoxProc ):                    /* shadow box variation */
  901.         case ( altDBoxProc + 4 ):                /* remain consistant w/ Apple */
  902.             thisRect.right -= 2;
  903.             thisRect.bottom -= 2;
  904.             FrameRect( &thisRect );
  905.             PenSize( 2, 2 );
  906.             if ( drawColor )
  907.                 RGBForeColor( &pat->cGray );
  908.             MoveTo( thisRect.left + 2, thisRect.bottom );
  909.             LineTo( thisRect.right, thisRect.bottom );
  910.             LineTo( thisRect.right, thisRect.top + 2 );
  911.             break;
  912.         default:                                /* plain box variation (plainDBox) and others */
  913.             PenPat( &pat->black );
  914.             FrameRect( &thisRect );
  915.             break;
  916.         }
  917.         
  918.         break;
  919.         
  920.     case ( wInGoAway ):
  921.     
  922.         SetRect( &thisRect,                         /* just toggle the goAway */
  923.             windowRect.left     + 3, 
  924.             windowRect.top         + 3,
  925.             windowRect.left     + 19,
  926.             windowRect.top         + 19
  927.          );
  928.         buttonState = !buttonState;
  929.         DrawGoAway( thisRect, buttonState, drawColor, theColors );        
  930.         break;
  931.         
  932.     case ( wInZoomIn ):
  933.     case ( wInZoomOut ):
  934.  
  935.         SetRect( &thisRect,                         /* just toggle the zoomBox */
  936.             windowRect.right     - 19, 
  937.             windowRect.top         + 3,
  938.             windowRect.right     - 3,
  939.             windowRect.top         + 19
  940.          );
  941.         buttonState = !buttonState;
  942.         DrawZoom( thisRect, buttonState, drawColor, theColors );
  943.         break;
  944.         
  945.     default:
  946.         break;
  947.         
  948.     }
  949. } /* end of DrawOnce() */
  950.  
  951. /*————————————————————
  952.             drawing my window
  953. ————————————————————*/
  954. DrawMyWindow( int var, WindowPtr window, long param )
  955. {
  956.     SysEnvRec        thisWorld;
  957.     CGrafPtr        wPort,
  958.                     savePort;
  959.     Boolean            hasColorQD;
  960.     
  961.     PenState        savePen;
  962.     RGBColor        savePnClr,
  963.                     saveBkClr;
  964.     PixPatHandle    savePnPat,
  965.                     saveBkPat,
  966.                     saveFillPat;
  967.  
  968.     PatsRec            patStore;
  969.     PatsPtr            pat;
  970.     
  971.     Rect            windowRect;
  972.     
  973.     savePnPat = nil;
  974.     
  975.     if ( !theWindow.visible ) return;
  976.     
  977.     pat = &patStore;
  978.         
  979.     if ( !SysEnvirons( 1, &thisWorld ) )
  980.         hasColorQD = thisWorld.hasColorQD;
  981.     else
  982.         hasColorQD = false;
  983.         
  984.     
  985.     if ( hasColorQD )
  986.     {
  987.         AuxWinHandle    theAuxWin;
  988.  
  989.         theAuxWin = nil;
  990.  
  991.         GetPort( &savePort );
  992.         GetCWMgrPort( &wPort );
  993.         SetPort( wPort );
  994.         
  995.         savePnPat = NewPixPat();
  996.         saveBkPat = NewPixPat();
  997.         saveFillPat = NewPixPat();
  998.         
  999.         CopyPixPat( wPort->pnPixPat, savePnPat );
  1000.         CopyPixPat( wPort->bkPixPat, saveBkPat );
  1001.         CopyPixPat( wPort->fillPixPat, saveFillPat );
  1002.         GetForeColor( &savePnClr );
  1003.         GetBackColor( &saveBkClr );
  1004.         
  1005.         pat->cBlack = PackGray( 0 );
  1006.         pat->cDark = PackGray( 0x4000 );
  1007.         pat->cGray = PackGray( 0x8000 );
  1008.         pat->cLight = PackGray( 0xC000 );
  1009.         pat->cWhite = PackGray( 0xFFFF );
  1010.         pat->cFrameL = pat->cLight;
  1011.         pat->cFrameD = pat->cDark;
  1012.         
  1013.         GetAuxWin( window, &theAuxWin );
  1014.         if ( theAuxWin )
  1015.         {
  1016.             HLockHi( (*theAuxWin)->awCTable );
  1017.                                 
  1018.             pat->cText = auxCTable->ctTable[2].rgb;
  1019.             pat->cTitle = auxCTable->ctTable[4].rgb;
  1020.             
  1021.     /*        The code below makes sure the System 7 colors are found even when the window color
  1022.                 table is defined with only 5 colors! This defines the outline colors of the
  1023.                 frame and buttons.    */
  1024.                 
  1025.             if ( auxCTable->ctSize < 12 )
  1026.                 GetAuxWin( nil, &theAuxWin );
  1027.             if ( auxCTable->ctSize >= 12 )
  1028.             {            
  1029.                 if ( auxCTable->ctTable[12].rgb.red + auxCTable->ctTable[12].rgb.green )
  1030.                 {
  1031.                     if ( !wCTHandle )    // Do the CTable now, if not already done!
  1032.                     {                                // We only use a ColorTable if System 7
  1033.                         Handle            theColors;
  1034.         
  1035.                         theColors = nil;
  1036.                         theColors = NewHandle( 40 );                // theColorTable!
  1037.  
  1038.                         if ( theColors )
  1039.                         {
  1040.                             int            i;
  1041.                     
  1042.                             HLock( theColors );
  1043.                             
  1044.                             (*(CTabHandle)theColors)->ctSeed = GetCTSeed();    //    Unique Seed
  1045.                             (*(CTabHandle)theColors)->ctFlags = 0;            //    Empty for CTables
  1046.                             (*(CTabHandle)theColors)->ctSize = 3;            //    4 Colors
  1047.                     
  1048.                             for ( i=0; i<=3; i++ )                            // Colors in sequence
  1049.                                 (*(CTabHandle)theColors)->ctTable[i].value = i;
  1050.                                 
  1051.                             (*(CTabHandle)theColors)->ctTable[1].rgb = pat->cGray;
  1052.                             (*(CTabHandle)theColors)->ctTable[3].rgb = pat->cBlack;
  1053.                             
  1054.                             HUnlock( theColors );
  1055.                             wCTHandle = theColors;
  1056.                         }
  1057.                     }
  1058.                     if( (auxCTable->ctTable[12].rgb.red &
  1059.                             auxCTable->ctTable[12].rgb.green &
  1060.                             auxCTable->ctTable[12].rgb.blue) != 0x3333 ) // disable Color Table if gray.
  1061.                     {
  1062.                         pat->cFrameL =  auxCTable->ctTable[11].rgb;
  1063.                         pat->cFrameD =  auxCTable->ctTable[12].rgb;
  1064.                     }
  1065.                     if ( wCTHandle )        // update Icon colors for Sys 7
  1066.                     {
  1067.                         (*(CTabHandle)(wCTHandle))->ctTable[0].rgb = pat->cFrameL;
  1068.                         (*(CTabHandle)(wCTHandle))->ctTable[2].rgb = pat->cFrameD;
  1069.                         if ( !(pat->cText.red + pat->cText.green + pat->cText.blue) )
  1070.                             pat->cText = pat->cFrameD;
  1071.                     }
  1072.                 } else
  1073.                     hasColorQD=false;
  1074.             }
  1075.             HUnlock( (*theAuxWin)->awCTable );
  1076.         } else
  1077.         {
  1078.             pat->cText = pat->cBlack;
  1079.             pat->cTitle = pat->cWhite;
  1080.         }
  1081.     }
  1082.     
  1083.     windowRect = (**theWindow.strucRgn).rgnBBox;
  1084.     
  1085. /*    Align the pattern to the position of the window to prevent shifting durring a drag. */
  1086.         
  1087.     pat->gray[0] = pat->gray[1] = (windowRect.left^windowRect.top) & 0x0001
  1088.         ?gray1Hex
  1089.         :gray2Hex;
  1090.     
  1091.     pat->black[0] = pat->black[1] = blackHex;
  1092.     pat->white[0] = pat->white[1] = whiteHex;
  1093.     GetPenState( &savePen );
  1094.     
  1095.     if ( hasColorQD )
  1096.     {
  1097.         RgnHandle    saveClip,
  1098.                     tempRgn;
  1099.         GDHandle    aDevice;
  1100.         
  1101.         saveClip = NewRgn();
  1102.         tempRgn = NewRgn();
  1103.         GetClip( saveClip );
  1104.  
  1105.         aDevice = GetDeviceList();
  1106.         do
  1107.         {
  1108.             if ( TestDeviceAttribute( aDevice, screenDevice ) &&
  1109.                                             TestDeviceAttribute( aDevice, screenActive ) )
  1110.             {
  1111.                 HLockHi( aDevice );
  1112.                 if ( RectInRgn( &(**aDevice).gdRect, saveClip ) )
  1113.                 {
  1114.                     RectRgn( tempRgn, &(**aDevice).gdRect );
  1115.                     SectRgn( saveClip, tempRgn, tempRgn );
  1116.                     SetClip( tempRgn );
  1117.                     DrawOnce( param, var, window, windowRect, pat,
  1118.                                                     ((**(**aDevice).gdPMap).cmpSize - 1 ));
  1119.                 }
  1120.                 HUnlock( aDevice);
  1121.             }
  1122.         } while ( (aDevice = GetNextDevice( aDevice )) != nil );
  1123.     
  1124.         SetClip( saveClip );
  1125.         DisposeRgn( saveClip );
  1126.         DisposeRgn( tempRgn );
  1127.     } else
  1128.         DrawOnce( param, var, window, windowRect, pat, false );
  1129.     
  1130.     SetPenState( &savePen );
  1131.     if ( savePnPat )        // Since hasColorQD may have changed, we check for presence of Handle.
  1132.     {
  1133.         RGBForeColor( &savePnClr );
  1134.         RGBBackColor( &saveBkClr );
  1135.         
  1136.         CopyPixPat( savePnPat, wPort->pnPixPat );
  1137.         CopyPixPat( saveBkPat, wPort->bkPixPat );
  1138.         CopyPixPat( saveFillPat, wPort->fillPixPat );
  1139.         DisposPixPat( savePnPat );
  1140.         DisposPixPat( saveBkPat );
  1141.         DisposPixPat( saveFillPat );
  1142.         
  1143.         SetPort( savePort );
  1144.     }
  1145. } /* end of DrawMyWindow() */
  1146.  
  1147. /*————————————————————
  1148.             draw a black and white Icon!
  1149. ————————————————————*/
  1150. PlotSICN( Rect theRect, Ptr theSICN )
  1151. {
  1152.     BitMap    srcBits;    /* built up around 'SICN' data so we can _CopyBits */
  1153.     GrafPtr    wPort;
  1154.     
  1155.     GetPort( &wPort );
  1156.  
  1157.     /* set up the small icon's bitmap */
  1158.     srcBits.baseAddr = theSICN;
  1159.     srcBits.rowBytes = 2;
  1160.     SetRect( &srcBits.bounds, 0, 0, 16, 16 );
  1161.  
  1162.                                 /* draw the small icon in the current grafport */
  1163.     CopyBits( &srcBits,&wPort->portBits,&srcBits.bounds,&theRect,srcCopy,nil );
  1164.  
  1165. } /* end of PlotSICN() */
  1166.  
  1167. /*————————————————————
  1168.             draw a color icon!
  1169. ————————————————————*/
  1170. PlotCICN( Rect theRect, Ptr theCICN, Handle theColors )
  1171. {
  1172.     PixMap            srcBits;    // built up around 'CICN' data so we can _CopyBits
  1173.      CGrafPtr        wPort;            
  1174.     RGBColor        savePnClr,
  1175.                     saveBkClr,
  1176.                     myRGB;
  1177.  
  1178.     GetForeColor( &savePnClr );
  1179.     myRGB = PackGray( 0x0000 );
  1180.     RGBForeColor( &myRGB );            // Black
  1181.     GetBackColor( &saveBkClr );
  1182.     myRGB = PackGray( 0xFFFF );
  1183.     RGBBackColor( &myRGB );            // White
  1184.  
  1185.      GetPort( &wPort );
  1186.      
  1187.     srcBits.baseAddr = theCICN;
  1188.      srcBits.rowBytes = 0x8004;        // bit 15 indicates PixMap
  1189.      SetRect( &srcBits.bounds, 0, 0, 16, 16 );
  1190.      srcBits.pmVersion = srcBits.packType = srcBits.pixelType = 0;
  1191.      srcBits.packSize = srcBits.planeBytes = srcBits.pmReserved = 0L;
  1192.      srcBits.hRes = srcBits.vRes = 72;
  1193.     srcBits.pixelSize = srcBits.cmpSize = 2;
  1194.      srcBits.cmpCount = 1;     
  1195.      srcBits.pmTable = (CTabHandle)theColors;                        // nil if not created
  1196.     
  1197.                                      //    draw the color icon in the current grafport
  1198.      CopyBits( &srcBits,*wPort->portPixMap,&srcBits.bounds,&theRect,srcCopy,nil );
  1199.      
  1200.     RGBForeColor( &savePnClr );
  1201.     RGBBackColor( &saveBkClr );
  1202.     
  1203. } /* end of PlotCICN() */
  1204.  
  1205. /*————————————————————
  1206.             CopyRight Notice
  1207. ————————————————————*/
  1208. CopyRight()
  1209. {
  1210.     /*    The Following Copyright Notice Is Not To Be Removed! Use Of This Code In Commercial
  1211.         Software Will Be By License Only. Contact Anthony D. Saxton, Of Elenay™ Creations
  1212.         For Licensing Information. Use Of This Code In FreeWare, Requires Only Contact Of
  1213.         Elenay™ Creations. This Copyright Applies To All Code Segments Of This WDEF. */
  1214.         
  1215.     Str63    Copyright = "Copyright©1993–Elenay™Creations,702/453–0270,"
  1216.                                 "All Rights Reserved";
  1217.     
  1218. }